package com.itheima.web.manager;

import cn.hutool.core.util.StrUtil;
import com.itheima.domain.db.UserInfo;
import com.itheima.domain.mongo.UserLocation;
import com.itheima.domain.vo.BaiduMapVo;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.service.db.UserInfoService;
import com.itheima.service.mongo.UserLocationService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class MapManager {
    @Reference
    UserInfoService userInfoService;
    @Reference
    UserLocationService userLocationService;
    //查询用户位置并在地图上显示

    public ResponseEntity findByPage(int pageNum, int pageSize) {
        PageBeanVo page = userInfoService.findByPage(pageNum, pageSize);
        return ResponseEntity.ok(page);
    }
    public ResponseEntity findBaiduMapById(Long userId) {
        //1.获取用户的个人信息和位置信息
        UserInfo userInfo = userInfoService.findById(userId);
        Map<Double, Double> map = userLocationService.findById(userId);
        //2.把信息封装到baiduMapVo中
        BaiduMapVo baiduMapVo = new BaiduMapVo();
        baiduMapVo.setUserId(userId);
        baiduMapVo.setNickname(userInfo.getNickname());
        baiduMapVo.setAvatar(userInfo.getAvatar());
        if(StrUtil.equals(userInfo.getGender(),"man")){
            baiduMapVo.setGender("男");
        }else {
            baiduMapVo.setGender("女");
        }
        baiduMapVo.setCity(userInfo.getCity());
        baiduMapVo.setAddress(userLocationService.findAddress(userId));
        baiduMapVo.setLongitude(map.get("x"));
        baiduMapVo.setLatitude(map.get("y"));

        return ResponseEntity.ok(baiduMapVo);
    }
}
